part of 'api.dart';

// ignore: library_private_types_in_public_api
extension ApiVideo on _Api {
  // 查询网黄
  Future<PornographyListResp?> fetchPornography({
    required int page,
    required int pageSize,
  }) async {
    try {
      final resp = await httpInstance.get(
        url: 'content/getPornographyList',
        queryMap: {
          'page': page,
          'pageSize': pageSize,
        },
        complete: PornographyListResp.fromJson,
      );
      return resp;
    } catch (e) {
      return null;
    }
  }

  // 短视频-关注
  Future<List<VideoBaseModel>?> fetchShortVideoFocusList({
    required int page,
    required int pageSize,
  }) =>
      _fetchShortVideo(
        page: page,
        pageSize: pageSize,
        recommend: false,
      );

  // 短视频-推荐
  Future<List<VideoBaseModel>?> fetchShortVideoRecommend({
    required int page,
    required int pageSize,
    bool? refresh,
  }) =>
      _fetchShortVideo(
          page: page, pageSize: pageSize, recommend: true, refresh: refresh);

  // 短视频
  Future<List<VideoBaseModel>?> _fetchShortVideo({
    required int page,
    required int pageSize,
    bool? recommend,
    bool? refresh,
  }) async {
    try {
      final resp = await httpInstance.get(
        url: 'video/queryBrushVideos',
        queryMap: {
          'page': page,
          'pageSize': pageSize,
          //排序：1-关注 2-推荐
          'sortType': recommend == true ? 2 : 1,
          "refresh": refresh,
        },
        complete: VideoBaseModel.fromJson,
      );
      return resp ?? [];
    } catch (e) {
      return null;
    }
  }

  Future<List<VideoBaseModel>?> fetchVideoHouse({
    required int page,
    required int pageSize,
    int? sortMark,
    int? videoType,
    String? tagsTitle,
  }) async {
    try {
      final resp = await httpInstance.get<VideoBaseModel>(
        url: 'video/queryVideoHouse',
        queryMap: {
          'page': page,
          'pageSize': pageSize,
          'sortMark': sortMark,
          'videoType': videoType,
          'tagsTitle': tagsTitle,
        },
        complete: VideoBaseModel.fromJson,
      );
      return resp ?? [];
    } catch (e) {
      return null;
    }
  }

  Future<AttentionUserVideosResp?> fetchAttentionUserVideo({
    required int page,
    required int pageSize,
    VideoSortType? sortType,
  }) async {
    try {
      final resp = await httpInstance.get(
        url: 'video/attentionUserVideo',
        queryMap: {
          'page': page,
          'pageSize': pageSize,
          'sortType': sortType,
        },
        complete: AttentionUserVideosResp.fromJson,
      );
      return resp;
    } catch (e) {
      return null;
    }
  }

  // 标签列表
  Future<List<TagsModel>?> fetchTagsList({int? parentId}) async {
    try {
      final resp = await httpInstance.get(
        url: 'video/tagsList',
        queryMap: {
          'parentId': parentId,
        },
        complete: TagsModel.fromJson,
      );
      return resp ?? [];
    } catch (e) {
      return null;
    }
  }
}
